package datasource;

import org.mybatis.generator.api.ConnectionFactory;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author: liyf
 * @create: 2025-02-23 22:32
 **/
public class MyConnectionFactory implements ConnectionFactory {

    private String driverClass;
    private String connectionURL;
    private String userId;
    private String password;


    @Override
    public Connection getConnection() throws SQLException {
        // 加载数据库驱动
        try {
            Class.forName(driverClass);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Database driver not found", e);
        }

        // 创建并返回数据库连接
        return DriverManager.getConnection(connectionURL, userId, password);
    }

    @Override
    public void addConfigurationProperties(Properties properties) {

    }

    public String getDriverClass() {
        return driverClass;
    }

    public void setDriverClass(String driverClass) {
        this.driverClass = driverClass;
    }

    public String getConnectionURL() {
        return connectionURL;
    }

    public void setConnectionURL(String connectionURL) {
        this.connectionURL = connectionURL;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
